/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ViewContato.java
 *
 * Created on 19/03/2012, 11:13:41
 */

package com.qp.smsmarketing.view;

import com.qp.smsmarketing.utils.JTextFieldFilter;
import com.qp.smsmarketing.utils.JTextFieldFilterNew;
import com.qp.smsmarketing.view.mbean.ContatoMBean;
import com.qp.smsmarketing.view.mbean.ContatoMBean;
import javax.swing.JOptionPane;

/**
 *
 * @author waldenilson
 */
public class ViewContato extends AbstractDialog {

    ContatoMBean conbean = new ContatoMBean();

    /** Creates new form ViewContato */
    public ViewContato() {
        initComponents();
        setTitle(".:: Contatos : SMS-Marketing ::.");
        setLocationRelativeTo(null);

//        tf_nome.setDocument(new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC,50));
        tf_email.setDocument(new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC,120));
//        tf_sobrenome.setDocument(new JTextFieldFilter(JTextFieldFilter.ALPHA_NUMERIC,50));
        tf_cel.setDocument(new JTextFieldFilterNew(JTextFieldFilterNew.NUMERIC,13));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel7 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        bt_salvar = new javax.swing.JButton();
        tf_nome = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableContato = new javax.swing.JTable();
        bt_novo = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        tf_sobrenome = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tf_anim = new javax.swing.JFormattedTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tf_email = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cb_sexo = new javax.swing.JComboBox();
        cb_ativo = new javax.swing.JCheckBox();
        jButton1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        ltGrupo = new javax.swing.JList();
        tf_cel = new javax.swing.JTextField();

        jLabel7.setText("jLabel7");

        setBackground(new java.awt.Color(255, 255, 255));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("CONTATOS");

        bt_salvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/qp/smsmarketing/resource/icon/16X16/apply.png"))); // NOI18N
        bt_salvar.setText("Salvar");
        bt_salvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_salvarActionPerformed(evt);
            }
        });

        jLabel3.setText("Sobrenome.:");

        jLabel2.setText("Nome.:");

        tableContato.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Código", "Nome", "Sobrenome", "Celular", "Ativo ?"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableContato.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableContatoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableContato);

        bt_novo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/qp/smsmarketing/resource/icon/16X16/add.png"))); // NOI18N
        bt_novo.setText("Novo");
        bt_novo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_novoActionPerformed(evt);
            }
        });

        jLabel4.setText("Celular.:");

        jLabel5.setText("Data Aniversário.:");

        try {
            tf_anim.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel6.setText("Grupo(s).:");

        jLabel8.setText("Email.:");

        jLabel9.setText("Sexo.:");

        cb_sexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));

        cb_ativo.setText("Contato Ativo ?");
        cb_ativo.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/qp/smsmarketing/resource/icon/16X16/cancel.png"))); // NOI18N
        jButton1.setText("Sair");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        ltGrupo.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane2.setViewportView(ltGrupo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel8)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 411, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(bt_novo)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(bt_salvar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1)))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(tf_nome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tf_sobrenome, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tf_cel, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cb_sexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(tf_anim, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(29, 29, 29))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(154, 154, 154)
                                .addComponent(cb_ativo))
                            .addComponent(tf_email, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tf_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tf_sobrenome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(cb_sexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(tf_anim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tf_cel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tf_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(cb_ativo))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(bt_novo)
                            .addComponent(bt_salvar)))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tableContatoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableContatoMouseClicked

        conbean.selecionarRegistro(this);
        
        // TODO add your handling code here:
    }//GEN-LAST:event_tableContatoMouseClicked

    private void bt_novoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_novoActionPerformed

        conbean.novoObjeto(this);
        // TODO add your handling code here:
    }//GEN-LAST:event_bt_novoActionPerformed

    private void bt_salvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_salvarActionPerformed

        String res = conbean.salvarObjeto(this);
        if ( res.equals("error") )
            JOptionPane.showMessageDialog
                    (null,"Ocorreu um erro em salvar modificações.\nTente novamente.","Erro",2);
        else if(res.equals("vnome"))
            JOptionPane.showMessageDialog
                    (null,"Informe um Nome válido.\nTente novamente.","Erro",2);
        else if(res.equals("vsobrenome"))
            JOptionPane.showMessageDialog
                    (null,"Informe um Sobrenome válido.\nTente novamente.","Erro",2);
        else if(res.equals("vdata"))
            JOptionPane.showMessageDialog
                    (null,"Informe a Data de Aniversário corretamente.\nTente novamente.","Erro",2);
        else if(res.equals("vemail"))
            JOptionPane.showMessageDialog
                    (null,"Informe um Email válido.\nTente novamente.","Erro",2);
        else if(res.equals("vsms"))
            JOptionPane.showMessageDialog
                    (null,"Informe um número de Celular válido, incluindo código de estado. (Ex: 9899998888 válido.\nTente novamente.","Erro",2);
        
        else
            conbean.buscarCrudContato(this);
        // TODO add your handling code here:
    }//GEN-LAST:event_bt_salvarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

        
        // TODO add your handling code here:
    }//GEN-LAST:event_formWindowClosed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        dispose();
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ViewContato().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bt_novo;
    private javax.swing.JButton bt_salvar;
    private javax.swing.JCheckBox cb_ativo;
    private javax.swing.JComboBox cb_sexo;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList ltGrupo;
    private javax.swing.JTable tableContato;
    private javax.swing.JFormattedTextField tf_anim;
    private javax.swing.JTextField tf_cel;
    private javax.swing.JTextField tf_email;
    private javax.swing.JTextField tf_nome;
    private javax.swing.JTextField tf_sobrenome;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the tableContato
     */
    public javax.swing.JTable getTableContato() {
        return tableContato;
    }

    /**
     * @param tableContato the tableContato to set
     */
    public void setTableContato(javax.swing.JTable tableContato) {
        this.tableContato = tableContato;
    }

    /**
     * @return the tf_desc
     */
    
    /**
     * @return the tf_nome
     */
    public javax.swing.JTextField getTf_nome() {
        return tf_nome;
    }

    /**
     * @param tf_nome the tf_nome to set
     */
    public void setTf_nome(javax.swing.JTextField tf_nome) {
        this.tf_nome = tf_nome;
    }

    /**
     * @return the cb_grupos
     */

    /**
     * @return the cb_sexo
     */
    public javax.swing.JComboBox getCb_sexo() {
        return cb_sexo;
    }

    /**
     * @param cb_sexo the cb_sexo to set
     */
    public void setCb_sexo(javax.swing.JComboBox cb_sexo) {
        this.cb_sexo = cb_sexo;
    }

    /**
     * @return the tf_anim
     */
    public javax.swing.JFormattedTextField getTf_anim() {
        return tf_anim;
    }

    /**
     * @param tf_anim the tf_anim to set
     */
    public void setTf_anim(javax.swing.JFormattedTextField tf_anim) {
        this.tf_anim = tf_anim;
    }

    /**
     * @return the tf_cel
     */
    public javax.swing.JTextField getTf_cel() {
        return tf_cel;
    }

    /**
     * @param tf_cel the tf_cel to set
     */
    public void setTf_cel(javax.swing.JFormattedTextField tf_cel) {
        this.tf_cel = tf_cel;
    }

    /**
     * @return the tf_email
     */
    public javax.swing.JTextField getTf_email() {
        return tf_email;
    }

    /**
     * @param tf_email the tf_email to set
     */
    public void setTf_email(javax.swing.JTextField tf_email) {
        this.tf_email = tf_email;
    }

    /**
     * @return the tf_sobrenome
     */
    public javax.swing.JTextField getTf_sobrenome() {
        return tf_sobrenome;
    }

    /**
     * @param tf_sobrenome the tf_sobrenome to set
     */
    public void setTf_sobrenome(javax.swing.JTextField tf_sobrenome) {
        this.tf_sobrenome = tf_sobrenome;
    }

    /**
     * @return the bt_novo
     */
    public javax.swing.JButton getBt_novo() {
        return bt_novo;
    }

    /**
     * @param bt_novo the bt_novo to set
     */
    public void setBt_novo(javax.swing.JButton bt_novo) {
        this.bt_novo = bt_novo;
    }

    /**
     * @return the bt_salvar
     */
    public javax.swing.JButton getBt_salvar() {
        return bt_salvar;
    }

    /**
     * @param bt_salvar the bt_salvar to set
     */
    public void setBt_salvar(javax.swing.JButton bt_salvar) {
        this.bt_salvar = bt_salvar;
    }

    /**
     * @return the cb_ativo
     */
    public javax.swing.JCheckBox getCb_ativo() {
        return cb_ativo;
    }

    /**
     * @param cb_ativo the cb_ativo to set
     */
    public void setCb_ativo(javax.swing.JCheckBox cb_ativo) {
        this.cb_ativo = cb_ativo;
    }

    /**
     * @return the ltGrupo
     */
    public javax.swing.JList getLtGrupo() {
        return ltGrupo;
    }

    /**
     * @param ltGrupo the ltGrupo to set
     */
    public void setLtGrupo(javax.swing.JList ltGrupo) {
        this.ltGrupo = ltGrupo;
    }

}
